import type { RouteRecordType } from '@/router'

import { defineStore } from 'pinia'
import { constantRoutes, asyncRoutes } from '@/router'
import { filterAsyncRoutes } from '@/router/generator'

export const useRouteStore = defineStore('route', {
  state: () => ({
    hasDynamicAddedRoute: false,
    routes: [] as RouteRecordType[]
  }),
  actions: {
    resetState() {
      this.$reset()
    },
    getAccessedRoutes(role: string) {
      const accessedRoutes = filterAsyncRoutes(asyncRoutes, role)
      this.routes = constantRoutes.concat(accessedRoutes)
      this.hasDynamicAddedRoute = true
      return accessedRoutes
    }
  },
  persist: false,
})
